﻿using CommunicationLib.Enums;
using CommunicationLib.Interface;
using CommunicationLib.Model;
using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;

namespace CommunicationLib.Base
{
    public abstract class CommunicationBase : ICommunication
    {
        /// <summary>
        /// 通讯模式
        /// </summary>
        public CommunicationMode CommunicationMode { get; internal set; } = CommunicationMode.TCP;
        /// <summary>
        /// 串口通讯
        /// </summary>
        public SerialPort SerialPort { get; internal set; }
        /// <summary>
        /// 网口通讯
        /// </summary>
        public TcpClient TcpClient { get; internal set; }
        /// <summary>
        /// 当前数据包
        /// </summary>
        public DataPackage Package;
        /// <summary>
        /// 与下位机的连接状态
        /// </summary>
        public bool Connected { get; internal set; }
        /// <summary>
        /// 环形缓冲区
        /// </summary>
        internal RingBufferManager RingBuffer { get; set; }
        /// <summary>
        /// 环形缓冲区的锁
        /// </summary>
        internal object lockRingBuffer { get; set; } = new object();

        /// <summary>
        /// 发送数据
        /// </summary>
        /// <param name="dataPackage"></param>
        public abstract void Send(DataPackage dataPackage);
        /// <summary>
        /// 开始
        /// </summary>
        /// <returns></returns>
        public abstract bool Start();
        /// <summary>
        /// 停止
        /// </summary>
        /// <returns></returns>
        public abstract bool Stop();
    }
}
